//
//  AppDelegate+RangersAppLog.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/8/22.
//

import Foundation
import RangersAppLog

extension AppDelegate {
    /// 初始化火山埋点
    func configRangersAppLog() {
        var appID = "10000003"
        #if DEBUG
            appID = "10000004"
        #endif
        
        /* 初始化SDK开始 */
        // 参数APPID: 参考2.1节获取
        let config = BDAutoTrackConfig(appID: appID)
        // 设置渠道，iOS一般默认App Store渠道
        config.channel = "Debug"

        // 设置私有化部署数据上送地址，参考2.2节获取，https://snssdk.yupaowang.com 例如 https://yourdomain.com，注意域名后不要加“/”
        BDAutoTrack.setRequestHostBlock { (vendor: BDAutoTrackServiceVendor, requestURLType: BDAutoTrackRequestURLType) -> String? in
            return "https://snssdk.yupaowang.com"
        }

        config.autoTrackEnabled = true // 全埋点开关，true开启，false关闭
        config.showDebugLog = true // true:开启日志，需要参考4.3设置Logger，false:关闭日志
        config.logNeedEncrypt = true // 加密开关，true开启，false关闭
        BDAutoTrack.setAppLauguage("zh/en/jp/fr")
        BDAutoTrack.setAppRegion("cn")
        BDAutoTrack.start(with: config)
        /* 初始化SDK结束 */
    }
    
    /// 注册火山埋点APP ID
    func registerRangersAppID(url: URL) -> Bool {
        var appID = "10000003"
        #if DEBUG
            appID = "10000004"
        #endif
        
        if(BDAutoTrackSchemeHandler.shared().handle(url, appID: appID, scene: nil)) {
            return true
        }
        
        return false
    }
}
